package com.google.gson.internal.bind;

import com.google.gson.a.a;
import com.google.gson.b.d;
import com.google.gson.internal.b;
import com.google.gson.internal.bind.TypeAdapter.Factory;
import com.google.gson.internal.f;
import com.google.gson.internal.j;
import java.io.IOException;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.LinkedHashMap;
import java.util.Map;

public class q implements Factory {
    private final f a;

    public q(f fVar) {
        this.a = fVar;
    }

    private s a(l lVar, Field field, String str, a aVar, boolean z, boolean z2) {
        final boolean a = j.a(aVar.a());
        final l lVar2 = lVar;
        final a aVar2 = aVar;
        final Field field2 = field;
        return new s(this, str, z, z2) {
            final TypeAdapter a = lVar2.a(aVar2);
            final /* synthetic */ q f;

            void a(com.google.gson.b.a aVar, Object obj) throws IOException, IllegalAccessException {
                Object b = this.a.b(aVar);
                if (b != null || !a) {
                    field2.set(obj, b);
                }
            }

            void a(d dVar, Object obj) throws IOException, IllegalAccessException {
                new x(lVar2, this.a, aVar2.b()).a(dVar, field2.get(obj));
            }
        };
    }

    private Map a(l lVar, a aVar, Class cls) {
        Map linkedHashMap = new LinkedHashMap();
        if (cls.isInterface()) {
            return linkedHashMap;
        }
        Type b = aVar.b();
        while (cls != Object.class) {
            AccessibleObject[] declaredFields = cls.getDeclaredFields();
            AccessibleObject.setAccessible(declaredFields, true);
            for (Field field : declaredFields) {
                boolean b2 = b(cls, field, b);
                boolean c = c(cls, field, b);
                if (b2 || c) {
                    s a = a(lVar, field, a(cls, field, b), a.a(b.a(aVar.b(), cls, field.getGenericType())), b2, c);
                    a = (s) linkedHashMap.put(a.g, a);
                    if (a != null) {
                        throw new IllegalArgumentException(b + " declares multiple JSON fields named " + a.g);
                    }
                }
            }
            aVar = a.a(b.a(aVar.b(), cls, cls.getGenericSuperclass()));
            cls = aVar.a();
        }
        return linkedHashMap;
    }

    protected String a(Class cls, Field field, Type type) {
        return field.getName();
    }

    protected boolean b(Class cls, Field field, Type type) {
        return !field.isSynthetic();
    }

    protected boolean c(Class cls, Field field, Type type) {
        return !field.isSynthetic();
    }

    public TypeAdapter create(l lVar, a aVar) {
        Class a = aVar.a();
        return !Object.class.isAssignableFrom(a) ? null : new r(this, this.a.a(aVar), a(lVar, aVar, a), null);
    }
}
